<template>
	<view class="page" @touchmove.stop.prevent="moveHandle">
		<view class="version">
			<text class="update">版本更新</text>
			<text class="version-num">云盟商桥：V {{versionInfo.version}}</text>
			<text class="size">大小：{{versionInfo.size}}M</text>
			<text class="time">更新时间： {{versionInfo.update_time}}</text>
			<view class="explain" >
				<text class="update-explain">更新内容</text>
				<text class="recover">{{versionInfo.note}}</text>
				<!-- <text class="recover">2.新增不花钱买东西功能</text> -->
			</view>
			
			<view class="next" @click="close">
				<text>下次再说</text>
			</view>
			<view class="install">
				<image src="/static/img/login.png"></image>
				<!-- <text @click="download(versionInfo.url)" >立即安装</text> -->
				<text @click="toDownload" >立即安装</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			versionInfo: {
				type: Object,
				default () {
					return {}
				}
			}
		},
		data() {
			return {
			}
		},
	
		methods: {
			moveHandle() {
			  return;
			},
			close() {
				// #ifdef APP-PLUS|| MP-WEIXIN
				this.$parent.closeUpdatePopup();
				// #endif
				// #ifndef APP-PLUS|| MP-WEIXIN
				this.$parent.$parent.closeUpdatePopup();
				// #endif
			},
			//安装
			install(url){
				
				uni.downloadFile({
					url:url,
					success: (res) => {
						if(res.statusCode === 200){
							console.log('下载成功')
						}
					},fail: (res)=>{
						console.log(res)
					}
					
					
				});

			},
			toDownload(){
				// #ifdef APP-PLUS|| MP-WEIXIN
				this.$parent.toDownload();
				// #endif
				// #ifndef APP-PLUS|| MP-WEIXIN
				this.$parent.$parent.toDownload();
				// #endif
			},
			download(url){
				var that = this
				var downloadApkUrl = url;
				console.log(downloadApkUrl)
				that.downloading = true
				this.close()
				uni.showToast({
					title:'后台下载中',
					icon:'none',
					duration:1000 
				})  
				const downloadTask = uni.downloadFile({
				    url: downloadApkUrl, //仅为示例，并非真实的资源
				    success: (res) => {
						console.log(res);
				        if (res.statusCode === 200) {
				            console.log('下载成功');
							console.log(res);
							that.downloading = false
							plus.runtime.install(res.tempFilePath,{},{},function(error){
							    uni.showToast({  
							        title: '安装失败', 
							        duration: 1500  
							    });  
							})
				        }
				    },fail: (res) => {
				    	 console.log(res);
				    }
				});
			},
		}
	}
</script>

<style>
	.page {
		position: fixed;
		z-index: 1000;
		background: rgba(0,0,0,0.4);
		width: 100%;
		height: 100vh;
	}
	.version {
		width: 650rpx;
		/* height: 796rpx; */
		min-height: 796rpx;
		height: auto;
		display: table;
		background: rgba(255,255,255,1);
		border-radius: 30rpx;
		margin-left: 50rpx;
		margin-top: 10vh;
		padding-bottom: 30rpx;
		overflow: auto;
	}
	.update {
		display: block;
		font-size: 34rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: rgba(51,51,51,1);
		margin-left: 258rpx;
		margin-top: 39rpx;
	}
	.version-num {
		display: block;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(51,51,51,1);
		margin-left: 60rpx;
		margin-top: 90rpx;
	}
	.size {
		display: block;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(51,51,51,1);
		margin-left: 60rpx;
		margin-top: 48rpx;
	}
	.time {
		display: block;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(51,51,51,1);
		margin-left: 60rpx;
		margin-top: 50rpx;
	}
	.explain {
		width: 379rpx;
		min-height: 129rpx;
		height: auto;
		display: table;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(51,51,51,1);
		margin-left: 60rpx;
		margin-top: 49rpx;
		/* overflow:hidden; 
		text-overflow:ellipsis;
		display:-webkit-box; 
		-webkit-box-orient:vertical;
		-webkit-line-clamp:4; */
	}
	.update-explain {
		font-size: 30rpx;
		color: #333;
	}
	.recover {
		display: block;
		font-size: 30rpx;
		color: #999;
		margin-left: 10rpx;
	}
	.next {
		display: block;
		width: 244rpx;
		height: 64rpx;
		line-height: 55rpx;
		background: rgba(230,230,230,1);
		border-radius: 8rpx;
		margin-left: 60rpx;
		margin-top: 99rpx;
	}
	.next text {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(102,102,102,1);
		margin-left: 63rpx;
	}
	.install {
		position: relative;
		display: block;
		width: 244rpx;
		height: 64rpx;
		line-height: 64rpx;
		margin-left: 346rpx;
		margin-top: -64rpx;
	}
	.install image {
		width: 244rpx;
		height: 64rpx;
	}
	.install text {
		position: absolute;
		left: 63rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(255,255,255,1);
	}
</style>
